let vm = new Vue({
    el: '#qualityPage',
    data: {
        list: [],
        msgPopover: true,
        auditPopover: false,  //审核弹出层
        timePopover: false,
        msg1: "",
        msg2: "",
        msg3: "",
        msg1Img: "",
        msg2Img: "",
        msg3Img: "",

        auditId: "",
        auditStatus: null,

        from: {
            num: "",
            price: "",
            total: "",
            time: "",
            remark: ""
        },

        minDate: new Date(2020, 0, 1),
        maxDate: new Date(2030, 10, 1),
        currentDate: new Date(),        

    },
    mounted() {
        this.getData();
    },
    methods: {
        getData() {
            let params = this.parseQueryString();
            leiku.post('http://dongtai.fsslpc.com/api/2021010823205554', params, res => {
                let data = res.data;
                if (data.length) {
                    this.list = data[0];
                    this.msg1 = data[0].goutongjilu;    //客户沟通
                    this.msg2 = data[0].cangjian;       //仓库检验
                    this.msg3 = data[0].yjian;          //部门意见
                    this.msg1Img = data[0].img1;
                    this.msg2Img = data[0].img2;
                    this.msg3Img = data[0].img3;

                    this.auditStatus = data[0].zt,      //审核状态
                    this.auditId = data[0].id

                }

            })
        },
        parseQueryString() {
            let url = document.location.toString();
            var obj = {};
            var arr = [];
            var key = "",
                value = "";
            var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
            for (var i in paraString) {
                arr = paraString[i].split("=");
                key = arr[0];
                value = arr[1];
                obj[key] = value;
            }
            return obj;
        },
        // 发起审核
        getAuditBtn() {
            this.$dialog.confirm({
                title: '确认发起审核？',
                message: '',
            }).then(() => {
                leiku.post("http://dongtai.fsslpc.com/api/2020121468457307", { id: this.auditId }, res => {
                    this.$notify({ type: "success", message: "发起审核！" })
                })
            }).catch(() => {});

        },
        // 审核
        auditBtn() {
            this.auditPopover = true;
            this.from = {
                num: this.list.tuihuoshuliang,
                price: this.list.danjia,
                total: this.list.amount,
                time: this.list.fktime,
                remark: this.list.remark                
            }
        },
        timeConfirm(v) {
            this.from.time = this.forDate(v);
            this.timePopover = false;
        },
        // 格式化日期
        formatter(type, val) {
            if (type === 'year') {
              return `${val}年`;
            } else if (type === 'month') {
              return `${val}月`;
            }else if (type === 'day') {
                return `${val}日`;
            }
            return val;
        }, 
        // 日期不足0补0 
        forDate(date) {
            return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2,'0')}-${(date.getDate()).toString().padStart(2,'0')}`;
        },                
        // 提交审核
        auditConfirm() {
            this.$dialog.confirm({
                title: '确认发起审核？',
                message: '',
            }).then(() => {
                let params = {
                    id: this.auditId,
                    rsid: this.list.bjqx,                
                    danjia: this.from.price,
                    sl: this.from.num,
                    amount: this.from.total,
                    remark: this.from.remark,
                    fktime: this.from.time,
                    bmida: this.list.bmid,  
                }
                leiku.post("http://dongtai.fsslpc.com/api/2020111043768857", params, res=> {
                    this.$notify({ type: "success", message: "提交成功！" })
                    this.auditPopover = false;
                    window.location.reload();
                })
            }).catch(() => {});

        },
    }
})